package datastructures;

public class Cache {
	
	int s,l,c,m;
	public String hitWritePolicy;
	public String missWritePolicy;
	public String associativity;
	int accessTime;
	public Object[][] cache;
	
	
	public final String writeThrough = "writethrough";
	public final String writeBack = "writeback";
	public final String fullAssociative = "Full Associative"; 
	public final String directMapping = "Direct Mapping";
	public final String setAssociative = "Set Associative";
	
	public Cache(int S, int L, int M, String hitWritePolicy, String missWritePolicy, int accessTime){
		
		c = S/L;
		cache = new Object[c][L];
		this.hitWritePolicy = hitWritePolicy;
		this.missWritePolicy = missWritePolicy;
		this.accessTime = accessTime;
		this.m = M;
		
	}
	
	public Object retrieve(int cacheLine, int index){
		
		return(cache[cacheLine][index]);
		
	}
	
	
	public int getC() {
		return c;
	}

	
	public int getM() {
		return m;
	}
	public int getL() {
		return l;
	}

	public void insert(Object o){
		
		boolean flag = false;
		
		for(int  i = 0; i < c; i++){
			
			for(int j = 0; j < l; j++){
				
				if(cache[i][j] == null){
					
					//check size and insert here.
					flag = true;
					
				}
				
			}
			
		}
		if(!flag){
			
			//do some replacement algorithm.
			
		}
		
	}
	
	public void setAssociativity(int associativity){
		
		if(associativity == 0)
			this.associativity = fullAssociative;
		else{
			
			if(associativity == 1)
				this.associativity = directMapping;
			else{
				
				this.associativity = setAssociative;
				this.m = associativity;
				
			}
			
		}
		
	}

}
